<template>
	<view class="pl52 pr52">
		<view class="fs58 fw mt40">验证码登录</view>
		<view class="mobilebox pl40 mt70">
			<u-input v-model="mobile" type="number" :border="false" height="90" placeholder="请输入手机号" trim />
		</view>
		<view class="pwdbox pl40 mt30 flex col-center pr26">
			<u-input v-model="codeMobile" type="number" :border="false" height="90" placeholder="请输入验证码" />
			<text @tap="getCode" class="color-red fs26">{{tips}}</text>
		</view>
		<view class="flex row-between col-center mt22">
			<text class="fs32" @tap='$jump("/pages/login/register")'>注册</text>
			<text class="fs24" @tap='$jump("/pages/login/retrievePwd")'>忘记密码</text>
		</view>

		<view class="loginbox mt50" @click="login">
			登录
		</view>
		<view class="color9 fs26 flex row-center mt40" @tap='$jump("/pages/login/login")'>
			密码登陆
		</view>
		<u-verification-code :seconds="seconds" ref="uCode" @change="codeChange">
		</u-verification-code>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '',
				seconds: 60,
				mobile: '',
				codeMobile: ''
			};
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.mobile == '') {
					this.$msg('手机号不能为空')
					return
				}
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$api.send_sms({
						mobile: this.mobile,
						type:'modify'
					}).then(res => {
						console.log(res)
						if(res.code==1) {
							this.$u.toast('验证码已发送');
							this.$refs.uCode.start();
						}
					})
					// setTimeout(() => {
					// 	uni.hideLoading();
					// 	// 这里此提示会被this.start()方法中的提示覆盖
					// 	this.$u.toast('验证码已发送');
					// 	// 通知验证码组件内部开始倒计时
					// 	this.$refs.uCode.start();
					// }, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			// end() {
			// 	this.$u.toast('倒计时结束');
			// },
			// start() {
			// 	this.$u.toast('倒计时开始');
			// },
			//登录
			login(){
				this.$api.codeLogin({mobile:this.mobile,code:this.codeMobile}).then(res=>{
					if(res.code==1) {
						uni.navigateTo({
							url:'/pages/home/home'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.mobilebox,
	.pwdbox {
		width: 100%;
		height: 90rpx;
		background: #F8F8F8;
		border-radius: 50rpx;

	}

	.loginbox {
		width: 100%;
		height: 90rpx;
		background: #D23030;
		border-radius: 50rpx;
		font-size: 30rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 90rpx;
		font-weight: 700;
	}
</style>
